home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / size / printMips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-16  |  3.2 KB  |  118 lines

  1. /* 
  2.  * sun23Print.c --
  3.  *
  4.  *    Contains the machine specific routine for printing the size if the
  5.  *    machine is a sun2 or sun3 (they both have the same a.out format).
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/cmds/size/RCS/printMips.c,v 1.4 90/02/16 13:47:18 rab Exp $";
  19. #endif /* not lint */
  20.  
  21. #include <assert.h>
  22.  
  23. #ifndef mips
  24. #define mips 1
  25. #endif
  26.  
  27. #ifndef LANGUAGE_C
  28. #define LANGUAGE_C 1
  29. #endif
  30.  
  31. #ifndef MIPSEL
  32. #define MIPSEL
  33. #endif
  34.  
  35. #if 0
  36. #include <ds3100.md/aouthdr.h>
  37. #include <ds3100.md/filehdr.h>
  38. #include <ds3100.md/scnhdr.h>
  39. #include <ds3100.md/sys/exec.h>
  40. #include <ds3100.md/nlist.h>
  41. #endif
  42.  
  43. #include <ds3100.md/a.out.h>
  44. #include "size.h"
  45.  
  46.  
  47. /*
  48.  *----------------------------------------------------------------------
  49.  *
  50.  * PrintMips --
  51.  *
  52.  *    Prints out the size information for a decStation 3100
  53.  *
  54.  * Results:
  55.  *    SUCCESS if size information was printed, FAILURE otherwise.
  56.  *
  57.  * Side effects:
  58.  *    Stuff is printed.
  59.  *
  60.  *----------------------------------------------------------------------
  61.  */
  62.  
  63. ReturnStatus
  64. PrintMips(fp, printName, fileName, printHeadings, bufferSize, buffer)
  65.     FILE    *fp;        /* file that header was read from */
  66.     Boolean    printName;    /* TRUE => print name of file */
  67.     char    *fileName;    /* name of file */
  68.     Boolean    printHeadings;    /* TRUE => print column headings */
  69.     int        bufferSize;    /* size of buffer */
  70.     char    *buffer;    /* buffer containing header */
  71. {
  72.  
  73.     struct exec         *header;
  74.     struct aouthdr    *aoutheader;
  75.     char        swappedHeader[sizeof(*header) * 2];
  76.     int            swappedSize = sizeof(swappedHeader);
  77.     int            status;
  78.  
  79.     assert(HEADERSIZE >= sizeof(struct exec));
  80.     if (bufferSize < sizeof(struct exec)) {
  81.     return FAILURE;
  82.     }
  83.     header = (struct exec *) buffer;
  84.     aoutheader = &header->ex_o;
  85.     /*
  86.      * See if the magic number is ok.  If it is not, and the format
  87.      * is not mips format, then swap to little-endian and see if
  88.      * that fixes it.
  89.      */
  90.     if (N_BADMAG(*aoutheader) && (FMT_MIPS_FORMAT != hostFmt)) {
  91.     status = Fmt_Convert("{h2w3h2h2w13}", FMT_MIPS_FORMAT, &bufferSize,
  92.         buffer, hostFmt, &swappedSize, swappedHeader);
  93.     if (status) {
  94.         fprintf(stderr, "Fmt_Convert returned %d.\n", status);
  95.         return FAILURE;
  96.     }
  97.     header = (struct exec *) swappedHeader;
  98.     aoutheader = &header->ex_o;
  99.     if (N_BADMAG(*aoutheader)) {
  100.         return FAILURE;
  101.     }
  102.     }
  103.     if (printHeadings) {
  104.     printf("%-7s %-7s %-7s %-7s %-7s\n", 
  105.            "text", "data", "bss", "dec", "hex");
  106.     }
  107.     printf("%-7d %-7d %-7d %-7d %-7x",
  108.            header->a_text, header->a_data, header->a_bss,
  109.            header->a_text + header->a_data + header->a_bss,
  110.            header->a_text + header->a_data + header->a_bss);
  111.     if (printName) {
  112.     printf("\t%s\n", fileName);
  113.     } else {
  114.     printf("\n");
  115.     }
  116.     return SUCCESS;
  117. }
  118.